package com.example.myapplication.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.data.HomeServlet;
import com.example.myapplication.tack_04.Stop;
import com.example.myapplication.tack_06.Books;
import com.example.myapplication.tack_07.Youth;
import com.example.myapplication.tack_08.Activity;
import com.example.myapplication.tack_09.LoveActivity;
import com.example.myapplication.tack_10.GovernmentActivity;
import com.example.myapplication.tack_11.HousingActivity;
import com.example.myapplication.tack_13.OutpatientActivity;
import com.example.myapplication.tack_14.WasteActivity;
import com.example.myapplication.tack_15.LawyerActivity;
import com.example.myapplication.tack_17.SmartBusActivity;
import com.example.myapplication.tack_18.InspectionActivity;
import com.example.myapplication.tack_19.FilmActivity;
import com.example.myapplication.tack_20.VolunteerActivity;
import com.example.myapplication.tack_21.PetHospitalActivity;
import com.example.myapplication.tack_22.MetroActivity;
import com.example.myapplication.tack_24.LogisticsActivity;
import com.example.myapplication.tack_25.TrafficManagementActivity;
import com.example.myapplication.tack_26.PayActivity;
import com.example.myapplication.tack_27.DataAnalysisActivity;
import com.example.myapplication.tack_29.JopActivity;
import com.example.myapplication.tack_30.TakeawayActivity;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class Servlet_02 extends RecyclerView.Adapter<Servlet_02.My> {
    private List<HomeServlet.RowsDTO> list;
    private Context context;
    private View view;

    public Servlet_02(List<HomeServlet.RowsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.servlet,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        if(position == list.size()-2){
            Glide.with(context).load(R.drawable.lszx).into(holder.imags);
            holder.name.setText(list.get(position).getServiceName());
        }else if(position == list.size()-1){
            Glide.with(context).load(R.drawable.yyjc).into(holder.imags);
            holder.name.setText(list.get(position).getServiceName());
        }else{
            Glide.with(context).load(OkHttpTool.URL + list.get(position).getImgUrl()).into(holder.imags);
            holder.name.setText(list.get(position).getServiceName());
        }
        switch (list.get(position).getId()){
            case 17://停车场
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, Stop.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 30://数字图书馆
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, Books.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 26://青年
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context,Youth.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 22://活动功能
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, Activity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 25://爱心公益
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, LoveActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 29://政府热线
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, GovernmentActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 20://找房子
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, HousingActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 5://
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, OutpatientActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 31://垃圾分类
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, WasteActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 3://巴士
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, SmartBusActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 50://律师
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, LawyerActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 51://预约检车
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, InspectionActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 18://看电影
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, FilmActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 32://志愿
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, VolunteerActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 23://宠物
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, PetHospitalActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 2://地铁
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, MetroActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 24://物流公司
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, LogisticsActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 9://智慧交管
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, TrafficManagementActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 7://生活缴费
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, PayActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 27://数据分析
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, DataAnalysisActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 21://找工作
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, JopActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 19://外卖
                holder.servlet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, TakeawayActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
        }
    }

    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private ImageView imags;
        private TextView name;
        private RelativeLayout servlet;
        public My(@NonNull View itemView) {
            super(itemView);
            imags = view.findViewById(R.id.imags);
            name = view.findViewById(R.id.name);
            servlet = view.findViewById(R.id.servlet);
        }
    }
}
